package cn.innosmart.aq.customize;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import cn.innosmart.aq.R;

/**
 * Created by David on 2015/7/29.
 */
public class DeviceFunctionPopupWindow extends PopupWindow {
    private TextView tvDeleteFail, tvReplaceDevice, tvDelete;
    private View mMenuView;
    private ListView lvDeviceFunction;

    public DeviceFunctionPopupWindow(Activity context, View.OnClickListener itemsOnClick) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.popupwindow_device_function, null);
        tvDeleteFail = (TextView) mMenuView.findViewById(R.id.tv_delete_fail);
        tvReplaceDevice = (TextView) mMenuView.findViewById(R.id.tv_replace_device);
        tvDelete = (TextView) mMenuView.findViewById(R.id.tv_delete);
        tvDeleteFail.setOnClickListener(itemsOnClick);
        tvReplaceDevice.setOnClickListener(itemsOnClick);
        tvDelete.setOnClickListener(itemsOnClick);
        this.setContentView(mMenuView);
        this.setWidth(ViewGroup.LayoutParams.FILL_PARENT);
        this.setHeight(ViewGroup.LayoutParams.FILL_PARENT);
        this.setFocusable(true);
//        this.setAnimationStyle(R.style.PopupAnimation);
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        this.setBackgroundDrawable(dw);
        mMenuView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                int height = mMenuView.findViewById(R.id.pop_layout).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
//                        dismiss();
                    }
                }
                return true;
            }
        });


    }
}
